<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/page/base.jsp"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>账号设置</title>
<link type="text/css" href="<%=path%>/manage/css/layout.css"
	rel="stylesheet" />
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery-1.4.4.min.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/easyTooltip.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery-ui-1.8.11.custom.min.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/jquery.wysiwyg.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/hoverIntent.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/superfish.js"></script>
<script type="text/javascript" src="<%=path%>/manage/js/custom.js"></script>
<script type="text/javascript"
	src="<%=path%>/manage/js/My97DatePicker/WdatePicker.js"></script>
<style type="text/css">
table {
	clear: both;
	font-size: 13px;
	padding: 1px;
	margin-bottom: 10px;
}

table td {
	border: 10px inherit;
	border-collapse: collapse;
}

table.alipay td.right {
	text-align: right;
}

table td.content {
	width: 650px;
	height: 27px
}

table td.title {
	width: 100px;
}

a.save {
	background:
		url("${pageContext.request.contextPath}/manage/images/btn_save.jpg");
	display: block;
	width: 16px;
	height: 16px;
	float: right;
}

a.edit {
	background:
		url("${pageContext.request.contextPath}/manage/images/btn_edit.jpg");
	display: block;
	width: 16px;
	height: 16px;
	float: right;
}

a.delete {
	background:
		url("${pageContext.request.contextPath}/manage/images/btn_delete.jpg");
	display: block;
	width: 16px;
	height: 16px;
	float: right;
}

a.add {
	color: #13a10c;
	font-size: 12px;
	text-decoration: none;
	font-size: 11px;
}

input.noborder {
	border: 0px solid #999999;
}
</style>
<script type="text/javascript">
	var editUrl = "${pageContext.request.contextPath}/account/editAccount.action";
	var delUrl = "${pageContext.request.contextPath}/account/delAccount.action";
	var addTemplate = "<td>"
			+ "APPID:<input type='text' name='#key_APP_ID' size='30' />"
			+ "密匙:<input type='text' name='#key_APP_KEY'  size='50' />"
			+ "<a href='#' class='delete' title='删除' data='{\"key\":\"#key\",\"type\":1}'></a>"
			+ "<a href='#'class='save' title='保存' data='{\"key\":\"#key\",\"type\":1}'></a>"
			+ "</td>";
	var addBtnTemplate = "<td colspan='2' valign='bottom'>"
			+ "<a href='#' class='add' title='添加绑定' data='{\"key\":\"#key\",\"type\":1}'>添加绑定</a></td>";
	var delTemplate = "<a href='#' class='delete' title='删除' data='{\"key\":\"#key\",\"type\":1}'></a>";
	var editTemplate = "<a href='#' class='edit' title='编辑' data='{\"key\":\"#key\",\"type\":1}'></a>";
	var aliPaySuffix = "ALI_PAY_";
	$(function() {
		var subFun = function($this) {
			var data = $.parseJSON($this.attr("data"));
			var $input = $("input[name^='" + data.key + "']");
			var params = [];
			var valid = true;
			$.each($input, function(i) {
				var $this = $(this);
				var key = $this.attr("name");
				var value = $this.val();
				if (value == "") {
					valid = false;
				}
				params.push({
					"key" : key,
					"value" : value,
					"type" : data.type
				});
			});
			if (valid == false) {
				alert("请输入完整值");
				return;
			}
			$.post(editUrl, {
				"params" : JSON.stringify(params)
			}, function(msg) {
				if (msg != "error") {
					alert("修改成功");
					$this.siblings("a.delete").remove();
					var $info = $(editTemplate.replace(/#key/g, data.key));
					$this.before($info);
					$info.click(function() {
						var $this = $(this);
						editFun($this);
					});
				}
			});
			$.each($input, function(i) {
				var $this = $(this);
				$this.addClass("noborder");
				$this.attr("readonly", "readonly");
			});
		};
		$("input[name='alipaySub']").click(function() {
			var $this = $(this);
			var data = $.parseJSON($this.attr("data"));
			var $input = $("input[name^='" + data.key + "']");
			var params = [];
			var valid = true;
			$.each($input, function(i) {
				var $this = $(this);
				var key = $this.attr("name").replace(/ALI_PAY_/g, "");
				var value = $this.val();
				if (value == "") {
					valid = false;
				}
				params.push({
					"key" : key,
					"value" : value,
					"type" : data.type
				});
			});
			if (valid == false) {
				alert("请输入完整值");
				return;
			}
			$.post(editUrl, {
				"params" : JSON.stringify(params)
			}, function(msg) {
				if (msg != "error") {
					alert("修改成功");
				}
			});
		});
		$("input[name='alipayReset']").click(function() {
			var isReset = confirm("是否重置支付账号配置 ?");
			if (isReset == false) {
				return;
			}
			var $this = $(this);
			var data = $.parseJSON($this.attr("data"));
			var $input = $("input[name^='" + data.key + "']");
			$.each($input, function(i) {
				var $this = $(this);
				$this.val("");
			});
		});
		$("a.add").click(function() {
			var $this = $(this);
			addConfig($this);
		});
		$("a.edit").click(function() {
			var $this = $(this);
			editFun($this);
		});
		var editFun = function($this) {
			var $input = $this.siblings("input")
			$input.removeClass("noborder");
			$input.removeAttr("readonly");
			var $data = $.parseJSON($this.attr("data"));
			var $info = $(delTemplate.replace(/#key/g, $data.key));
			$this.before($info);
			$info.click(function() {
				var $this = $(this);
				delConfig($this, true);
			});
			$this.siblings("a.save").one("click", function() {
				var $this = $(this);
				subFun($this);
			});
			$this.remove();
		}
		var addConfig = function($this) {
			var $data = $.parseJSON($this.attr("data"));
			var $info = $(addTemplate.replace(/#key/g, $data.key))
			$this.parents('tr').append($info);
			$this.parent().remove();
			$info.find("a.delete").click(function() {
				var $this = $(this);
				delConfig($this);
			});
			$info.find("a.save").one("click", function() {
				var $this = $(this);
				subFun($this);
			});
		}
		var delConfig = function($this, remote) {
			var $data = $.parseJSON($this.attr("data"));
			var $info = $(addBtnTemplate.replace(/#key/g, $data.key));
			var $input = $("input[name^='" + $data.key + "']");
			var keys = [];
			$input.each(function() {
				keys.push($(this).attr("name"));
			});
			if (remote == true) {
				$.ajax({
					url : delUrl,
					type : "POST",
					data : {
						params : keys.join(",")
					},
					success : function(msg) {
						if (msg == "success") {
							alert("删除成功");
						} else {
							alert("删除失败,请稍后再试");
						}
					}
				});
			}
			$info.find("a.add").click(function() {
				var $this = $(this);
				addConfig($this);
			});
			$this.parents('tr').append($info);
			$this.parent().remove();
		}
	});
</script>
</head>
<body>
	<!-- 模块显示 -->
	<div>
		<p class="sitemap">当前位置：客户端功能管理 > 账号配置</p>
		<h1>账号配置</h1>
		<div>
			<!-- Tabs -->
			<div id="tabs">
				<ul>
					<li><a href="#tabs-1">分享账号配置</a></li>
					<li><a href="#tabs-2">支付宝账号配置</a></li>
				</ul>
				<div id="tabs-1">
					<table>
						<tr>
							<td class="title"><img alt=""
								src="${pageContext.request.contextPath }/manage/images/icon_weibo_xl.jpg">新浪微博:
							</td>
							<c:if test="${configs['T_SINA_APP_ID'] ne null}">
								<td class="content">APPID:<input type="text"
									name="T_SINA_APP_ID" class="noborder" readonly="readonly"
									value="${configs['T_SINA_APP_ID'] }" size="30" />密匙:<input
									type="text" name="T_SINA_APP_KEY" class="noborder"
									readonly="readonly" value="${configs['T_SINA_APP_KEY'] }"
									size="40" /> <a href="#" class="edit" title="编辑"
									data='{"key":"T_SINA","type":1}'></a> <a href="#" class="save"
									title="保存" data='{"key":"T_SINA","type":1}'></a>
								</td>
							</c:if>
							<c:if test="${configs['T_SINA_APP_ID'] eq null}">
								<td colspan="2" valign="bottom"><a href="#" class="add"
									title="添加绑定" data='{"key":"T_SINA","type":1}'>添加绑定</a></td>
							</c:if>
						</tr>
						<tr>
							<td class="title"><img alt=""
								src="${pageContext.request.contextPath }/manage/images/icon_weibo_tx.jpg">腾讯微博:
							</td>
							<c:if test="${configs['T_TENCENT_APP_ID'] ne null}">
								<td class="content">APPID:<input type="text"
									name="T_TENCENT_APP_ID" class="noborder" readonly="readonly"
									value="${configs['T_TENCENT_APP_ID'] }" size="30" />密匙:<input
									type="text" name="T_TENCENT_APP_KEY" class="noborder"
									readonly="readonly" value="${configs['T_TENCENT_APP_KEY'] }"
									size="40" /><a href="#" class="edit" title="编辑"
									data='{"key":"T_TENCENT","type":1}'></a><a href="#"
									class="save" title="保存" data='{"key":"T_TENCENT","type":1}'></a>
								</td>
							</c:if>
							<c:if test="${ configs['T_TENCENT_APP_ID'] eq null}">
								<td colspan="2" valign="bottom"><a href="#" class="add"
									title="添加绑定" data='{"key":"T_TENCENT","type":1}'>添加绑定</a></td>
							</c:if>
						</tr>
						<tr>
							<td class="title"><img alt=""
								src="${pageContext.request.contextPath }/manage/images/icon_weixin.jpg">微信:
							</td>
							<c:if test="${configs['WX_APP_ID'] ne null }">
								<td class="content">APPID:<input type="text"
									name="WX_APP_ID" class="noborder" readonly="readonly"
									value="${configs['WX_APP_ID'] }" size="30" />密匙:<input
									type="text" name="WX_APP_KEY" class="noborder"
									readonly="readonly" value="${configs['WX_APP_KEY'] }" size="40" /><a
									href="#" class="edit" title="编辑" data='{"key":"WX","type":1}'></a><a
									href="#" class="save" title="保存" data='{"key":"WX","type":1}'></a>
								</td>
							</c:if>
							<c:if test="${configs['WX_APP_ID'] eq null }">
								<td colspan="2" valign="bottom"><a href="#" class="add"
									title="添加绑定" data='{"key":"WX","type":1}'>添加绑定</a></td>
							</c:if>
						</tr>
					</table>
				</div>
				<div id="tabs-2">
					<table class="alipay">
						<tr>
							<td class="right"><img alt=""
								src="${pageContext.request.contextPath }/manage/images/icon_alipay.jpg"></td>
							<td></td>
						</tr>
						<tr>
							<td class="right">合作商ID</td>
							<td><input type="text" name="ALI_PAY_PART_ID" size="30"
								value="${configs['PART_ID']}"></td>
						</tr>
						<tr>
							<td class="right">MD5密匙</td>
							<td><input type="text" name="ALI_PAY_PRIVATE_KEY"
								value="${configs['PRIVATE_KEY'] }" size="30" /></td>
						</tr>
						<tr>
							<td class="right">卖家账号(账号名)</td>
							<td><input type="text" name="ALI_PAY_SELLER_ACCOUNT"
								value="${configs['SELLER_ACCOUNT'] }" size="30" /></td>
						</tr>
						<tr>
							<td></td>
							<td><input type="button" value="提交" name="alipaySub"
								data='{"key":"ALI_PAY","type":2}'> <input type="button"
								value="重置" name="alipayReset" data='{"key":"ALI_PAY","type":2}'></td>
						</tr>
					</table>
				</div>
			</div>
		</div>
	</div>
</body>
</html>
